/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.control.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.risk.control.dto.RiskControlMeasureDTO;
import com.hopes.bizz.risk.control.dto.RiskControlMeasureExcelDTO;
import com.hopes.bizz.risk.control.entity.RiskControlMeasureEntity;
import com.hopes.bizz.risk.control.entity.RiskMeasureTaskConfigEntity;
import com.hopes.bizz.risk.control.entity.RiskUnitEntity;
import com.hopes.bizz.risk.control.entity.RiskUnitEventEntity;
import com.hopes.bizz.risk.control.mapper.RiskControlMeasureMapper;
import com.hopes.bizz.risk.control.mapper.RiskObjectMapper;
import com.hopes.bizz.risk.control.mapper.RiskUnitEventMapper;
import com.hopes.bizz.risk.control.mapper.RiskUnitMapper;
import com.hopes.bizz.risk.control.service.RiskControlMeasureService;
import com.hopes.bizz.risk.control.service.RiskMeasureTaskConfigService;
import com.hopes.bizz.risk.control.support.RiskExportExcelSupport;
import com.hopes.bizz.risk.control.support.RiskImportExcelSupport;
import com.hopes.bizz.risk.control.vo.*;
import com.hopes.boss.common.core.constant.CommonConstants;
import com.hopes.boss.common.core.exception.BizException;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.entity.ImportResultVO;
import com.hopes.boss.common.entity.ValidateImportBO;
import com.hopes.boss.common.excel.vo.ErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.validation.BindingResult;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 风险管控措施
 *
 * @author pig
 * @date 2023-07-19 16:16:03
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RiskControlMeasureServiceImpl extends ServiceImpl<RiskControlMeasureMapper, RiskControlMeasureEntity> implements RiskControlMeasureService {

    private final RiskUnitMapper riskUnitMapper;
    private final RiskObjectMapper riskObjectMapper;
    private final RiskUnitEventMapper riskUnitEventMapper;
    private final RiskExportExcelSupport riskExportExcelSupport;
    private final RiskImportExcelSupport riskImportExcelSupport;
    private final RiskMeasureTaskConfigService riskMeasureTaskConfigService;

    @Override
    public Page<RiskControlMeasureVO> listPage(Page<RiskControlMeasureVO> page, RiskControlMeasureDTO riskControlMeasureDTO) {
        riskControlMeasureDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
        final Page<RiskControlMeasureVO> selectPage = baseMapper.listControlMeasure(page, riskControlMeasureDTO);
        /* 数据处理 */
        final Map<Long, List<RiskControlMeasureVO>> map = selectPage.getRecords().stream().filter(e ->
                Objects.nonNull(e.getRiskObjectId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskObjectId));
        map.forEach((k, v) -> {
            v.get(0).setRowCount(v.size());
        });
        final Map<Long, List<RiskControlMeasureVO>> unitMap = selectPage.getRecords().stream().filter(e ->
                Objects.nonNull(e.getRiskUnitId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskUnitId));
        unitMap.forEach((k, v) -> {
            v.get(0).setUnitRowCount(v.size());
        });
        final Map<Long, List<RiskControlMeasureVO>> eventMap = selectPage.getRecords().stream().filter(e ->
                Objects.nonNull(e.getRiskEventId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskEventId));
        eventMap.forEach((k, v) -> {
            v.get(0).setEventRowCount(v.size());
        });
        return selectPage;
    }

    @Override
    public Page<RiskControlMeasureVO> listWithTaskPage(Page<RiskControlMeasureVO> page, RiskControlMeasureDTO riskControlMeasureDTO) {
        riskControlMeasureDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
        return baseMapper.listWithTaskPage(page, riskControlMeasureDTO);
    }

    @Override
    public boolean save(RiskControlMeasureEntity riskControlMeasureEntity) {
        Assert.notNull(riskControlMeasureEntity.getRiskEventId(), "所属风险事件Id不可为空");
        final RiskUnitEventEntity eventEntity = riskUnitEventMapper.selectById(riskControlMeasureEntity.getRiskEventId());
        if (Objects.isNull(eventEntity)) {
            throw new BizException("所属风险事件数据获取失败");
        }
        riskControlMeasureEntity.setRiskUnitId(eventEntity.getRiskUnitId());
        return baseMapper.insert(riskControlMeasureEntity) > 0;
    }

    @Override
    public RiskControlMeasureVO getById(Serializable id) {
        final RiskControlMeasureEntity controlMeasureEntity = baseMapper.selectById(id);
        final RiskControlMeasureVO controlMeasureVO = new RiskControlMeasureVO();
        BeanUtils.copyProperties(controlMeasureEntity, controlMeasureVO);
        if (Objects.nonNull(controlMeasureVO.getRiskUnitId())) {
            final RiskUnitEntity riskUnitEntity = riskUnitMapper.selectOne(
                    Wrappers.<RiskUnitEntity>lambdaQuery().eq(RiskUnitEntity::getId, controlMeasureVO.getRiskUnitId()).select(RiskUnitEntity::getRiskObjectId));
            controlMeasureVO.setRiskObjectId(Optional.ofNullable(riskUnitEntity).map(RiskUnitEntity::getRiskObjectId).orElse(null));
        }
        return controlMeasureVO;
    }

    @Override
    public boolean updateById(RiskControlMeasureEntity riskControlMeasureEntity) {
        Assert.notNull(riskControlMeasureEntity.getRiskEventId(), "所属风险事件Id不可为空");
        final RiskUnitEventEntity eventEntity = riskUnitEventMapper.selectById(riskControlMeasureEntity.getRiskEventId());
        if (Objects.isNull(eventEntity)) {
            throw new BizException("所属风险事件数据获取失败");
        }
        riskControlMeasureEntity.setRiskUnitId(eventEntity.getRiskUnitId());
        return baseMapper.updateById(riskControlMeasureEntity) > 0;
    }

    @Override
    public List<RiskControlMeasureVO> listIdentify(Long riskUnitId) {
        final RiskControlMeasureDTO param = new RiskControlMeasureDTO();
        param.setRiskUnitId(riskUnitId);
        param.setDelFlag(CommonConstants.STATUS_NORMAL);
        final List<RiskControlMeasureVO> controlMeasureVOList = this.baseMapper.queryForList(param, "risk_event_id");
        final Map<Long, List<RiskControlMeasureVO>> map = controlMeasureVOList.stream().collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskEventId));
        map.forEach((k, v) -> v.get(0).setRowCount(v.size()));
        return controlMeasureVOList;
    }

    @Override
    public List<RiskControlMeasureVO> listDetailed(RiskControlMeasureDTO riskControlMeasureDTO) {
        riskControlMeasureDTO.setDelFlag(CommonConstants.STATUS_NORMAL);
        final List<RiskControlMeasureVO> controlMeasureVOList = this.baseMapper.listRiskDetailed(riskControlMeasureDTO, "risk_object_id, risk_unit_id, risk_event_id");

        final Map<Long, List<RiskControlMeasureVO>> map = controlMeasureVOList.stream().filter(e -> Objects.nonNull(e.getRiskObjectId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskObjectId));
        map.forEach((k, v) -> {
            v.get(0).setRowCount(v.size());
        });

        final Map<Long, List<RiskControlMeasureVO>> unitMap = controlMeasureVOList.stream().filter(e -> Objects.nonNull(e.getRiskUnitId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskUnitId));
        unitMap.forEach((k, v) -> {
            v.get(0).setUnitRowCount(v.size());
        });

        final Map<Long, List<RiskControlMeasureVO>> eventMap = controlMeasureVOList.stream().filter(e -> Objects.nonNull(e.getRiskEventId())).collect(Collectors.groupingBy(RiskControlMeasureVO::getRiskEventId));
        eventMap.forEach((k, v) -> {
            v.get(0).setEventRowCount(v.size());
        });

        return controlMeasureVOList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeBatchByIds(Collection<?> list) {
        if (CollUtil.isEmpty(list)) {
            return true;
        }
        final List<RiskMeasureTaskConfigEntity> riskMeasureTaskConfigList = riskMeasureTaskConfigService.list(Wrappers.<RiskMeasureTaskConfigEntity>lambdaQuery().in(RiskMeasureTaskConfigEntity::getRiskControlId, list));
        if (CollUtil.isNotEmpty(riskMeasureTaskConfigList)) {
            riskMeasureTaskConfigService.removeBatchByIds(riskMeasureTaskConfigList.stream().map(RiskMeasureTaskConfigEntity::getId).collect(Collectors.toList()));
        }
        return baseMapper.deleteBatchIds(list) > 0;
    }

    /**
     * 导入风险辨识管控数据
     *
     * @param riskIdentifyExcelVOList 风险辨识数据
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R importExcelIdentify(Long riskUnitId, List<RiskIdentifyExcelVO> riskIdentifyExcelVOList, BindingResult bindingResult) throws Exception {
        Assert.notNull(riskUnitId, "风险单元Id不可为空！");
        // 1、校验导入的数据
        final List<RiskIdentifyExcelVO> identifyExcelVOList = riskImportExcelSupport.restoreMergeData(riskIdentifyExcelVOList, RiskIdentifyExcelVO.class);
        if (CollectionUtil.isEmpty(identifyExcelVOList)) {
            return R.failed("导入数据为空");
        }
        // 2、校验字典数据
        final List<ErrorMessage> errorMessageList = riskImportExcelSupport.validateDictData(bindingResult, identifyExcelVOList, RiskIdentifyExcelVO.class);
        if (CollUtil.isNotEmpty(errorMessageList)) {
            final ImportResultVO importResultVO = new ImportResultVO();
            importResultVO.setFailedNum(errorMessageList.size());
            importResultVO.setErrorMessageList(errorMessageList);
            return R.failed(importResultVO);
        }
        // 3、校验数据是否重复
        final List<ErrorMessage> errorMessageModList = riskImportExcelSupport.validateEventIsExist(bindingResult, riskUnitId, identifyExcelVOList);
        if (CollUtil.isNotEmpty(errorMessageModList)) {
            final ImportResultVO importResultVO = new ImportResultVO();
            importResultVO.setFailedNum(errorMessageModList.size());
            importResultVO.setErrorMessageList(errorMessageModList);
            return R.failed(importResultVO);
        }
        // 4、校验评估方法
        final List<ErrorMessage> errorMessageEmList = riskImportExcelSupport.validateEvaluateMethodAndDesc(bindingResult, riskUnitId, identifyExcelVOList);
        if (CollUtil.isNotEmpty(errorMessageEmList)) {
            final ImportResultVO importResultVO = new ImportResultVO();
            importResultVO.setFailedNum(errorMessageEmList.size());
            importResultVO.setErrorMessageList(errorMessageEmList);
            return R.failed(importResultVO);
        }

        final AtomicInteger index = new AtomicInteger(1);
        identifyExcelVOList.forEach(item -> item.setIndex(String.valueOf(index.getAndIncrement())));
        // 2、构建导入数据
        final List<RiskUnitEventVO> eventVOList = riskImportExcelSupport.buildRiskIdentifyImport(identifyExcelVOList, riskUnitId);
        // 3、导入
        if (CollectionUtil.isEmpty(eventVOList)) {
            return R.failed("导入风险事件数据为空");
        }
        importIdentifyData(eventVOList);
        return R.ok();
    }

    /**
     * 导入风险管控措施
     *
     * @param importVoList 导入的数据
     */
    private void importIdentifyData(List<RiskUnitEventVO> importVoList) {
        if (CollectionUtil.isEmpty(importVoList)) {
            return;
        }
        for (RiskUnitEventVO unitEventVO : importVoList) {
            final RiskUnitEventEntity eventEntity = new RiskUnitEventEntity();
            BeanUtils.copyProperties(unitEventVO, eventEntity);
            riskUnitEventMapper.insert(eventEntity);
            /* 管控措施 */
            final List<RiskControlMeasureVO> riskControlMeasureList = unitEventVO.getRiskControlMeasureList();
            if (CollectionUtil.isEmpty(riskControlMeasureList)) {
                continue;
            }
            riskControlMeasureList.forEach(item -> {
                item.setRiskEventId(eventEntity.getId());
                item.setRiskUnitId(eventEntity.getRiskUnitId());
            });
            /* 批量保存管控措施 */
            importIdentifyControlList(riskControlMeasureList);
        }
    }

    private void importIdentifyControlList(List<RiskControlMeasureVO> riskControlMeasureList) {
        if (CollectionUtil.isEmpty(riskControlMeasureList)) {
            return;
        }
        // 1、保存管控措施
        baseMapper.batchSaveByVO(riskControlMeasureList);
        // 2、保存管控任务配置
        final List<RiskMeasureTaskConfigVO> riskMeasureTaskConfigVOList = new ArrayList<>();
        for (RiskControlMeasureVO controlMeasureVO : riskControlMeasureList) {
            final List<RiskMeasureTaskConfigVO> taskConfigList = controlMeasureVO.getRiskMeasureTaskConfigList();
            if (CollectionUtil.isEmpty(taskConfigList)) {
                continue;
            }
            taskConfigList.forEach(item -> {
                item.setRiskControlId(controlMeasureVO.getId());
                item.setRiskUnitId(controlMeasureVO.getRiskUnitId());
                item.setRiskEventId(controlMeasureVO.getRiskEventId());
            });
            riskMeasureTaskConfigVOList.addAll(taskConfigList);
        }
        // 2、保存管控任务配置
        if (CollectionUtil.isNotEmpty(riskMeasureTaskConfigVOList)) {
            final boolean b = riskMeasureTaskConfigService.saveBatchByVO(riskMeasureTaskConfigVOList);
            log.debug("风险辨识批量保存任务配置结果：{}", b);
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public R importExcelDetail(List<RiskDetailExcelVO> riskDetailExcelVOList, BindingResult bindingResult) throws Exception {
//        // 1、校验导入的数据
//        final List<RiskDetailExcelVO> detailExcelVOList = riskImportExcelSupport.restoreMergeData(riskDetailExcelVOList, RiskDetailExcelVO.class);
//        if (CollectionUtil.isEmpty(detailExcelVOList)) {
//            return R.failed("导入数据为空！");
//        }
//
//        // 2、校验字典数据
//        final List<ErrorMessage> errorMessageList = riskImportExcelSupport.validateDictData(bindingResult, detailExcelVOList, RiskDetailExcelVO.class);
//        if (CollUtil.isNotEmpty(errorMessageList)) {
//            final ImportResultVO importResultVO = new ImportResultVO();
//            importResultVO.setFailedNum(errorMessageList.size());
//            importResultVO.setErrorMessageList(errorMessageList);
//            return R.failed(importResultVO);
//        }
//
//        // 3、校验评估方法
//        final List<ErrorMessage> errorMessageEmList = riskImportExcelSupport.validateEvaluateMethodAndDesc(bindingResult, detailExcelVOList);
//        if (CollUtil.isNotEmpty(errorMessageEmList)) {
//            final ImportResultVO importResultVO = new ImportResultVO();
//            importResultVO.setFailedNum(errorMessageEmList.size());
//            importResultVO.setErrorMessageList(errorMessageEmList);
//            return R.failed(importResultVO);
//        }
//
//        final AtomicInteger index = new AtomicInteger(1);
//        detailExcelVOList.forEach(item -> item.setIndex(String.valueOf(index.getAndIncrement())));
//        /* 风险管控措施 */
//        final List<RiskControlMeasureVO> controlMeasureList = riskImportExcelSupport.buildRiskControlMeasureList(detailExcelVOList);
//        if (CollectionUtil.isEmpty(controlMeasureList)) {
//            return R.failed("导入的数据为空");
//        }
//        for (RiskControlMeasureVO controlMeasureVO : controlMeasureList) {
//            // 1、风险对象
//            final RiskObjectVO riskObject = controlMeasureVO.getRiskObject();
//            final RiskObjectEntity riskObjectEntity = new RiskObjectEntity();
//            BeanUtils.copyProperties(riskObject, riskObjectEntity);
//            final List<RiskObjectEntity> riskObjectEntities = riskObjectMapper.selectList(Wrappers.lambdaQuery(riskObjectEntity));
//            if (CollectionUtil.isEmpty(riskObjectEntities)) {
//                riskObjectMapper.insert(riskObjectEntity);
//                riskObject.setId(riskObjectEntity.getId());
//            } else {
//                BeanUtils.copyProperties(riskObjectEntities.get(0), riskObject);
//            }
//            // 2、风险单元
//            final RiskUnitVO riskUnit = controlMeasureVO.getRiskUnitEvent().getRiskUnit();
//            riskUnit.setRiskObjectId(riskObject.getId());
//            final RiskUnitEntity riskUnitEntity = new RiskUnitEntity();
//            BeanUtils.copyProperties(riskUnit, riskUnitEntity);
//            final List<RiskUnitEntity> riskUnitEntityList = riskUnitMapper.selectList(Wrappers.lambdaQuery(riskUnitEntity));
//            if (CollectionUtil.isEmpty(riskUnitEntityList)) {
//                riskUnitMapper.insert(riskUnitEntity);
//                riskUnit.setId(riskUnitEntity.getId());
//            } else {
//                BeanUtils.copyProperties(riskUnitEntityList.get(0), riskUnit);
//            }
//            controlMeasureVO.setRiskUnitId(riskUnit.getId());
//
//            // 3、风险事件
//            final RiskUnitEventVO riskUnitEvent = controlMeasureVO.getRiskUnitEvent();
//            riskUnitEvent.setRiskUnitId(riskUnit.getId());
//            final RiskUnitEventEntity eventEntity = new RiskUnitEventEntity();
//            BeanUtils.copyProperties(riskUnitEvent, eventEntity);
//            final List<RiskUnitEventEntity> riskUnitEventEntityList = riskUnitEventMapper.selectList(Wrappers.lambdaQuery(eventEntity));
//            if (CollectionUtil.isEmpty(riskUnitEventEntityList)) {
//                riskUnitEventMapper.insert(eventEntity);
//                riskUnitEvent.setId(eventEntity.getId());
//            } else {
//                BeanUtils.copyProperties(riskUnitEventEntityList.get(0), riskUnitEvent);
//            }
//            controlMeasureVO.setRiskEventId(riskUnitEvent.getId());
//        }
//        importIdentifyControlList(controlMeasureList);
        return R.ok("风险管控清单导入成功");
    }


    /**
     * 导出风险辨识管控
     *
     * @param riskControlMeasureDTO 过滤条件
     * @param response              http响应对象
     */
    @Override
    public void exportExcelIdentify(RiskControlMeasureDTO riskControlMeasureDTO, HttpServletResponse response) throws Exception {
        /* 根据风险单元查询管控措施 */
        final List<RiskControlMeasureVO> riskControlMeasureVOList = listIdentify(riskControlMeasureDTO.getRiskUnitId());
        final List<RiskIdentifyExcelVO> list = riskExportExcelSupport.IdentifyData(riskControlMeasureVOList);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setIndex(String.valueOf(i + 1));
        }
        if (CollUtil.isEmpty(list)) {
            throw new BizException("内容为空，不可导出");
        }
        //final RiskIdentifyMergeStrategy mergeStrategy = new RiskIdentifyMergeStrategy(list);

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("Accept-Ranges", "bytes");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8");
        EasyExcel
                .write(response.getOutputStream())
                .sheet("风险管控措施")
                .head(RiskIdentifyExcelVO.class)
                .useDefaultStyle(true)
                // .registerWriteHandler(mergeStrategy)
                .doWrite(list);
    }


    /**
     * 导出风险管控清单
     *
     * @param riskControlMeasureDTO 过滤条件
     * @param response              http响应对象
     * @throws Exception
     */
    @Override
    public void exportExcelDetail(RiskControlMeasureDTO riskControlMeasureDTO, HttpServletResponse response) throws Exception {
        final RiskUnitEventVO riskUnitEventVO = new RiskUnitEventVO();
        riskUnitEventVO.setDelFlag(CommonConstants.STATUS_NORMAL);
        riskUnitEventVO.setRiskUnitId(riskControlMeasureDTO.getRiskUnitId());
        riskUnitEventVO.setRiskObjectId(riskControlMeasureDTO.getRiskObjectId());
        final List<RiskUnitEventEntity> riskUnitEventList = riskUnitEventMapper.queryForList(riskUnitEventVO);
        final Map<Long, RiskUnitEventEntity> unitEventMap = riskUnitEventList.stream().collect(Collectors.toMap(RiskUnitEventEntity::getId, e -> e));
        /* 风险管控清单 */
        final List<RiskControlMeasureVO> riskControlMeasureVOList = this.listDetailed(riskControlMeasureDTO);
        final List<RiskDetailExcelVO> list = riskExportExcelSupport.detailedData(riskControlMeasureVOList, unitEventMap);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setIndex(String.valueOf(i + 1));
        }
        if (CollUtil.isEmpty(list)) {
            throw new BizException("内容为空，不可导出");
        }
        // final RiskDetailedMergeStrategy mergeStrategy = new RiskDetailedMergeStrategy(list);

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("Accept-Ranges", "bytes");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8");
        EasyExcel
                .write(response.getOutputStream())
                .sheet("风险管控清单")
                .head(RiskDetailExcelVO.class)
                .useDefaultStyle(true)
                //.registerWriteHandler(mergeStrategy)
                .doWrite(list);
    }

    @Override
    public List<RiskControlMeasureEntity> getByRiskUnitIdList(List<Long> riskUnitIdList) {
//        if (CollectionUtil.isEmpty(riskUnitIdList)) {
//            return new ArrayList<>();
//        }
//        return this.baseMapper.queryByRiskUnitIdList(riskUnitIdList);
        return null;
    }

    @Override
    public RiskControlMeasureEntity getByUid(String uid) {
        return baseMapper.getByUid(uid);
    }

    @Override
    public ValidateImportBO<RiskControlMeasureExcelDTO> validateImport(List<RiskControlMeasureExcelDTO> excelDTOList) {
        ValidateImportBO<RiskControlMeasureExcelDTO> bo = new ValidateImportBO<>();
        List<ErrorMessage> errorMessageList = new ArrayList<>();
        List<RiskControlMeasureExcelDTO> saveList = new ArrayList<>(excelDTOList);
        int successNum = excelDTOList.size();
        int failedNum = 0;

        bo.setErrorMessages(errorMessageList);
        bo.setSaveList(saveList);
        bo.setSuccessNum(successNum);
        bo.setFailedNum(failedNum);
        return bo;
    }

    @Override
    public RiskControlMeasureEntity importDtoToEntity(RiskControlMeasureExcelDTO excelDto) {
        RiskControlMeasureEntity entity = new RiskControlMeasureEntity();
        BeanUtils.copyProperties(excelDto, entity);
        return entity;
    }

    @Override
    public RiskControlMeasureExcelVO exportEntityToVo(RiskControlMeasureEntity entity) {
        RiskControlMeasureExcelVO excelVO = new RiskControlMeasureExcelVO();
        BeanUtils.copyProperties(entity, excelVO);
        return excelVO;
    }


}
